from odoo import api, models, fields, _
from odoo.exceptions import ValidationError, UserError
import datetime
import logging

_logger = logging.getLogger(__name__)


class StockMoveLine(models.Model):
    _inherit = 'stock.move.line'

    @api.constrains('state')
    def check_state_constraints(self):
        data = {
            "docType": "API_LPN_STOCK",
            "updateType": "UPDATE",
            "data": []
        }
        data_list = []
        for record in self:
            data_list.append({
                "org_id": "0001",
                "mtrl_code": "string",  # 物料编码
                "store_code": "string",  # 仓库编码  需要考虑仓库同步
                "business_type": "string",  # 业务类型  由ERP定义，告知MES这边有哪些，用数字代替，从1开始编号，比如领料申请
                "business_no": "string",  # 业务编码  比如领料申请时，传领料单编号
                "lotno": "string",  # 生产批次
                "lpn_qty": 0,  # 数量  减库存时为负数
                "mfd_date": "",  # 生产日期  格式：yyyy-MM-dd
                "lpn": None,
                "position_code": None,
                "remark": None,
                "sup_code": None,
                "qlty_stat": 2,
                "datecode": None,
                "mf_code": None,
                "mf_mtrl_code": None,
                "fifo_date": None,
                "exp_date": None,
                "ro_date": None,
                "cust_code": None,
                "cust_mtrl_code": None,
                "prod_code": None,
                "prod_version": None,
                "po_code": None,
                "asn": None
            })
        data['data'] = data_list
        # 执行上传MES
